﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Global
{
	public class Global
	{
		public static Dictionary<string, string> convertArgs(string[] args)
		{
			try
			{
				Dictionary<string, string> argDic = new Dictionary<string, string>();

				int noNameParamIndex = 1;
				for (int i = 0; i < args.Length; i++)
				{
					string argName = noNameParamIndex.ToString();

					if (args[i][0] == '/')
					{
						argName = args[i].Substring(1);
						i++;
					}
					string argValue = args[i];
					argDic.Add(argName, argValue);
				}
				return argDic;
			}
			catch (Exception ex)
			{
				Console.WriteLine("convertArgs error");
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.StackTrace);
				Environment.Exit(1);
				return null;
			}
		}

		public static bool parseHeadDate(string s,out string headDateRemovedString,ref DateTime date)
		{

			headDateRemovedString = s;

			if (s.Length <= 0) return false;

			if (s[0] != '[') return false;

			int p = s.IndexOf(']');
			if (p < 0) return false;

			string dateString = s.Substring(1, p - 2);
			
			if (!DateTime.TryParse(dateString,out date)) return false;

			headDateRemovedString = s.Substring(p + 1);

			return true;

	
		}
	}
}
